package co.fitstart.coach.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.service.impl.GenericServiceImpl;

import co.fitstart.coach.dao.CourseRoundDao;
import co.fitstart.coach.service.CourseRoundService;
import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.course.round.RoundCoursewareStatus;
import co.fitstart.entity.course.round.RoundStatus;
import co.fitstart.entity.principal.Principal;

/**
 * 
 * @author wangliwang
 *
 */
@Service("courseRoundService")
public class CourseRoundServiceImpl extends GenericServiceImpl<CourseRound> implements CourseRoundService {
    
    @Dynamic
    private CourseRoundDao courseRoundDao;

    /* (non-Javadoc)
     * @see co.fitstart.coach.service.CourseRoundService#list(co.fitstart.entity.principal.Principal, co.fitstart.entity.course.round.RoundCoursewareStatus)
     */
    public List<CourseRound> list(Principal coach, RoundCoursewareStatus roundCoursewareStatus) {
        if(roundCoursewareStatus.isFinish()) {
            return courseRoundDao.listFinish(coach, roundCoursewareStatus, RoundStatus.FINISH);
        } else {
            List<RoundStatus> courseStatus = new ArrayList<>();
            
            courseStatus.add(RoundStatus.PREPARE);
            courseStatus.add(RoundStatus.READY);
            courseStatus.add(RoundStatus.HOLD);
            courseStatus.add(RoundStatus.ACTIVATE);
            courseStatus.add(RoundStatus.EXPIRE);
            
            return courseRoundDao.listUnfinish(coach, roundCoursewareStatus, courseStatus);
        }
        
    }
    
    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.CourseRoundService#listCancel(co.fitstart.entity.principal.Principal)
     */
    public List<CourseRound> listCancel(Principal coach) {
        return courseRoundDao.listCancel(coach, RoundStatus.CANCEL);
    }
    
    /* (non-Javadoc)
     * @see co.fitstart.coach.service.CourseRoundService#load(java.lang.Long, co.fitstart.entity.principal.Principal, co.fitstart.entity.course.round.RoundCoursewareStatus)
     */
    public CourseRound load(Long id, Principal coach, RoundCoursewareStatus roundCoursewareStatus) {
        return courseRoundDao.load(id, coach, roundCoursewareStatus);
    }

}
